// let host = "cn-guangzhou-intranet.log.aliyuncs.com";
let host = "cn-guangzhou.log.aliyuncs.com";
let project = "lhj-monitor";
let logStore = "monitor-store";

function getExtraData() {
	return {
		title: document.title,
		timestamp: Date.now()
	};
}
class SendTracker {
	constructor() {
		this.url = `http://${project}.${host}/logstores/${logStore}/track`; // 上报的路径
		this.xhr = new XMLHttpRequest();
	}
	send(data = {}) {
		let log = { ...data };
		// 阿里云规定不能有
		for (let key in log) {
			if (typeof log[key] === "number") {
				log[key] = `${log[key]}`;
			}
		}
		console.log(log);
		let body = JSON.stringify({
			__logs__: [log]
		});
		this.xhr.open("POST", this.url, true);
		this.xhr.setRequestHeader("Content-Type", "application/json");
		this.xhr.setRequestHeader("x-log-apiversion", "0.6.0");
		this.xhr.setRequestHeader("x-log-bodyrawsize", body.length);
		this.xhr.send(body);
	}
}

export default new SendTracker();
